<?php
require_once '../model/conn.php';
require_once '../model/artRep.php';
header('Content-Type: application/json');

$cid = isset($_POST['cid']) ? intval($_POST['cid']) : 0;

$sql = "select * from tbl_user where uname ='$_POST[uname]'";
$uid = intval(exec_select($sql)[0]['uid']);

$content = $_POST['content'];

$who = isset($_POST['who']) ? intval($_POST['who']) : 0;

$aid = isset($_POST['aid']) ? intval($_POST['aid']) : 0;


if ($aid <= 0 && $cid <= 0 && $who <= 0) {
  echo json_encode(['code' => 500, 'msg' => '请求出错']);
  exit;
}

$insertRid = insertRep($cid, $uid, $content, $who, $aid);
$sql1 = "select * from tbl_user where uid =$who";
$uName = exec_select($sql1)[0]['uName'];
if ($insertRid > 0) {
  echo json_encode([
    'code' => 200,
    'msg' => '回复成功',
    'uid' => $uid,
    'uname' => $uName,
    'rid' => $insertRid
  ]);
} else {
  echo json_encode(['code' => 500, 'msg' => '回复失败']);
}


?>